/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 2009-8-12
 * Time: 23:35:11
 * To change this template use File | Settings | File Templates.
 */

/**
 * www.faceye.com 网络支持系统
 * 作者:宋海鹏 ecsun@sohu.com/myecsun@hotmail.com/QQ:82676683
 * 说明:javascripts 工具类
 * 提供按需加载JS文件功能
 */

/**
 * 动态加载JS文件
 */
var Faceye = {
    version : 1.0,
    /**
     *简单取得httpRequest
     */
    httpRequest : function() {
        var xRequest = null;
        if (window.XMLHttpRequest) {
            xRequest = new XMLHttpRequest();
        } else if (window.ActiveXObject) {
            xRequest = new ActiveXObject("MsXml2.XmlHttp");
        }
        return xRequest;
    },
    /**
     *简单的加载文件
     */
    load : function(src) {
        var headerDom = document.getElementsByTagName('head').item(0);
        var jsDom = document.createElement('script');
        jsDom.type = 'text/javascript';

        for (i = 0; i < document.getElementsByTagName("script").length; i++) {
            if (document.getElementsByTagName("script").item(i).src == src) {
                return;
            }
        }
        jsDom.src = src;
        headerDom.appendChild(jsDom);
    },
    /**
     *通过ajax方式加载js
     */
    ajaxLoad : function(src) {
        var xRequest = this.httpRequest();
        xRequest.open('GET', src, true);
        xRequest.send(null);
        var headerDom = document.getElementsByTagName('head')
                .item(0);
        var jsDom = document.createElement('script');
        jsDom.type = 'text/javascript';
        jsDom.language = 'javascript';
        jsDom.defer = true;
        jsDom.text = xRequest.responseText;
        headerDom.appendChild(jsDom);

    }
};  